package org.qpcr.community.device.web;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
import org.qpcr.community.device.entity.CalibrationCmdEntity;
import org.qpcr.community.device.service.CalibrationCmdService;
import org.qpcr.community.device.web.request.CalibrationCmdSendRequest;
import org.qpcr.community.device.web.request.FluorescenceCalibrationDataExportSingleRequest;
import org.qpcr.community.device.web.request.FluorescenceCalibrationDataExportWholeRequest;
import org.qpcr.community.device.web.request.TemperatureCalibrationExportRequest;
import org.qpcr.community.device.web.response.CalibrationResponse;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

@RestController
@RequestMapping("/device/calibration-cmd")
@Authorize(ignore = true)
@Resource(id = "calibration-cmd", name = "校准指令记录")
@Slf4j
@Tag(name = "校准指令记录接口")
@RequiredArgsConstructor
public class CalibrationCmdController implements ReactiveServiceCrudController<CalibrationCmdEntity, String> {
    @Getter
    private final CalibrationCmdService service;

    @PostMapping("/send")
    public Mono<String> sendCmd(@RequestBody CalibrationCmdSendRequest request) {
        return service.sendCmd(request);
    }

    @PostMapping("/send-response")
    public Mono<String> sendResponse(@RequestBody CalibrationResponse response) {
        return service.sendResponse(response);
    }

    @GetMapping("/{messageId}/get")
    public Mono<CalibrationCmdEntity> getCmd(@PathVariable String messageId) {
        return service.getByMessageId(messageId);
    }

    @GetMapping("read-record/{deviceId}/{moduleCode}")
    public Mono<CalibrationCmdEntity> readRecord(@PathVariable String deviceId,@PathVariable String moduleCode) {
        return service.readRecord(deviceId,moduleCode);
    }


    @GetMapping("/fluorescence-calibration/read-record/{deviceId}")
    public Mono<List<CalibrationCmdEntity>> fluorescenceCalibrationReadRecord(@PathVariable String deviceId) {
        return service.fluorescenceCalibrationReadRecord(deviceId);
    }


    @PostMapping("/edit-remark")
    public Mono<Integer> editRecord(@RequestBody CalibrationCmdEntity entity) {
        return service.editRemark(entity);
    }

    @PostMapping("export-temperature-calibration-result")
    @Authorize(ignore = true)
    public Mono<Void> exportTemperatureCalibrationResult(@RequestBody TemperatureCalibrationExportRequest exportRequest, ServerHttpResponse response) {
        return service.exportTemperatureCalibrationResult(exportRequest, response);
    }


    @PostMapping("export-fluorescence-calibration-data-single")
    @Authorize(ignore = true)
    public Mono<Void> exportFluorescenceCalibrationDataSingle(@RequestBody FluorescenceCalibrationDataExportSingleRequest req,String deviceId,String moduleId, ServerHttpResponse response) {
        return service.exportFluorescenceCalibrationDataSingle(req,deviceId,moduleId, response);
    }

    @PostMapping("export-fluorescence-calibration-data-whole")
    @Authorize(ignore = true)
    public Mono<Void> exportFluorescenceCalibrationDataWhole(@RequestBody FluorescenceCalibrationDataExportWholeRequest req, String deviceId,String currentCalibrationParam,String beforeCalibrationParam, ServerHttpResponse response) {
        return service.exportFluorescenceCalibrationDataWhole(req,deviceId,currentCalibrationParam,beforeCalibrationParam, response);
    }
}